package Servlet.camera;

import Dao.UserDao;
import Manage.Camera;
import Manage.User;
import Utils.mybatisUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;
import java.util.List;


public class caminsertServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取表单发来的数据
        String username=request.getParameter("username");
        String id=request.getParameter("ID");
        String street=request.getParameter("street");
        Camera camera=new Camera();
//        if (!"".equals(id)&&!"".equals(street)){
//            camera.setId(Integer.parseInt(id));
            camera.setStreet(street);
            camera.setUsername(username);
//        }
        SqlSession session= mybatisUtils.getSqlSession();
        UserDao dao= session.getMapper(UserDao.class);
//        List<Camera> list= dao.selectcam(username);
        boolean flag=true;
//        for (Camera c:list){
//            if(c.getId()==Integer.parseInt(id)){
//                flag=false;
//                response.getWriter().print("已经有重复id");
//            }
//        }
        if (!"".equals(camera.getStreet())&&flag) {
            //增
            dao.caminsert(camera);
            response.getWriter().print("操作成功");
        }
        session.commit();
        session.close();
    }
}
